﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using WebAuth.Bussiness;
using WebAuth.DAO;
using WebAuth.Models;

namespace WebAuth.Controllers
{
    [ApiController]
    // [Route("[controller]")]
    public class API : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<API> _logger;

        public API(ILogger<API> logger)
        {
            _logger = logger;
        }

        [Route("set")]
        [HttpPost]
        public string[] Set([FromQuery] string what)
        {
            var l = new List<string> {what};
            return l.ToArray();
        }

        [Route("test")]
        [HttpGet]
        public string Test([FromQuery] string userId,string authItemId)
        {
            /*User user = new User();
            user.Id = "1";
            user.Name = "a";
            // user.AuthChildrenIds = new List<string>() {"sss", "ds"};
            // user.BindAuthChildren<AuthBinder>();
            AuthBinder binder = new AuthBinder();
            var binders = new List<AuthBinder>();
            binders.Add(binder);
            // user.Binders = binders;*/
            /*UapDbContext dbContext = DbManager.GetDbContext();
            var cachmanager = CacheManager.GetCacheManager();
            cachmanager.LoadCache();
            cachmanager.GetModelById("1",out User user);
            user.Name = "me";
            // dbContext.AuthBinders.Add(binder);
            // dbContext.Users.Add(user);
            dbContext.SaveChanges();*/


           var authManager= AuthManager.GetAuthManager();
           if (authManager.CheckAuth(userId, authItemId))
               return "ok";
           return "negative";

        }
    }
}